package com.me.modules.report.controller;

import com.me.modules.common.controller.BaseController;
import com.me.modules.common.utils.*;
import com.me.modules.report.service.IncReportService;
import com.me.modules.sys.entity.CodeEntity;
import com.me.modules.sys.service.CodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.*;


/**
 * 事件报表
 *
 * @author lill
 * @email lill5270@163.com
 * @date 2019-01-16 17:20:30
 */
@Controller
@RequestMapping("/report/increport")
public class IncReportController extends BaseController{
	@Autowired
	private IncReportService incReportService;
	@Autowired
	private CodeService codeService;


	/**
	 * 列表
	 */
	@RequestMapping("/incClosePie")
//	@RequiresPermissions("srminfo:list")
//	@SysLog("查询变更列表")
	public String incClosePie(@RequestParam Map<String, Object> params, Model model , HttpServletRequest request){
		List<Object> list =incReportService.getIncClosePie(params);
		model.addAttribute("params",params);
		model.addAttribute("data",JsonUtil.getJsonByObj(list));
		return "report/incident/IncPieClose";
	}

	/**
	 * 列表
	 */
	@RequestMapping("/incGaugeOverstock")
//	@RequiresPermissions("srminfo:list")
//	@SysLog("查询变更列表")
	public String incGaugeOverstock(@RequestParam Map<String, Object> params, Model model , HttpServletRequest request){
		Map map =incReportService.getIncGaugeOverstock(params);
		model.addAttribute("params",params);
		model.addAttribute("data",JsonUtil.getJsonByObj(map));
		return "report/incident/IncGaugeOverstock";
	}

	/**
	 * 列表
	 */
	@RequestMapping("/incGridTodayClose")
//	@RequiresPermissions("srminfo:list")
//	@SysLog("查询变更列表")
	public String incGridTodayClose(@RequestParam Map<String, Object> params, Model model , HttpServletRequest request){
//		List<Object> list =incReportService.incGridTodayClose();
		model.addAttribute("params",params);
//		model.addAttribute("data",JsonUtil.getJsonByObj(list));
		return "report/incident/IncGridTodayClose";
	}

	/**
	 * 列表
	 */
	@RequestMapping("/IncLineOrginMonth")
//	@RequiresPermissions("srminfo:list")
//	@SysLog("查询变更列表")
	public String IncLineOrginMonth(@RequestParam Map<String, Object> params, Model model , HttpServletRequest request){
		List list =new ArrayList();
		List<CodeEntity> codeList  =codeService.queryChildsByMark("incOrigin");
		list.add(codeList);
		Date endDate= (Date) params.get("endDate");
		if(endDate==null){
			params.put("endDate",new Date());
		}
		List listColumn = new ArrayList();
		for (CodeEntity code :codeList) {
			params.put("inc_origin",code.getValue());
			List<Object> month =incReportService.IncLineOrginMonth(params);
			listColumn.add(month);
		}
		list.add(listColumn);
		model.addAttribute("params",params);
		model.addAttribute("data",JsonUtil.getJsonByObj(list));
		return "report/incident/IncLineOrginMonth";
	}

	/**
	 * 列表
	 */
	@RequestMapping("/IncChainDayNumber")
//	@RequiresPermissions("srminfo:list")
//	@SysLog("查询变更列表")
	public String IncChainDayNumber(@RequestParam Map<String, Object> params, Model model , HttpServletRequest request){
		Date endDate= (Date) params.get("endDate");
		if(endDate==null){
			params.put("endDate",Utils.parse(new  Date(),"yyyy-MM"));
		}
		List<Object> list =incReportService.IncLineDayNumber(params);
		model.addAttribute("params",params);
		model.addAttribute("data",JsonUtil.getJsonByObj(list));
		return "report/incident/IncChainDayNumber";
	}

	/**
	 * 列表
	 */
	@RequestMapping("/IncLineDayNumber")
//	@RequiresPermissions("srminfo:list")
//	@SysLog("查询变更列表")
	public String IncLineDayNumber(@RequestParam Map<String, Object> params, Model model , HttpServletRequest request){
		Date endDate= (Date) params.get("endDate");
		if(endDate==null){
			params.put("endDate",Utils.parse(new  Date(),"yyyy-MM"));
		}
		List<Object> list =incReportService.IncLineDayNumber(params);
		model.addAttribute("params",params);
		model.addAttribute("data",JsonUtil.getJsonByObj(list));
		return "report/incident/IncLineDayNumber";
	}


	/**
	 * 列表
	 */
	@RequestMapping("/IncYoyDayNumber")
//	@RequiresPermissions("srminfo:list")
//	@SysLog("查询变更列表")
	public String IncYoyDayNumber(@RequestParam Map<String, Object> params, Model model , HttpServletRequest request){
		List list =new ArrayList();
		List codeList  =new ArrayList();
		List listColumn = new ArrayList();
		Date beginDate= (Date) params.get("beginDate");
		Date endDate= (Date) params.get("endDate");

		Map<String, Object> oldparams=new HashMap<String, Object>();
		if(beginDate==null){
			oldparams.put("endDate",Utils.parse(new  Date(),"yyyy-MM"));
			List<Object> newList =incReportService.IncLineDayNumber(oldparams);
			codeList.add(Utils.parse(new  Date(),"yyyy-MM"));
			listColumn.add(newList);
		}else{
			oldparams.put("endDate",Utils.parse(beginDate,"yyyy-MM"));
			codeList.add(Utils.parse(beginDate,"yyyy-MM"));
			List<Object> newList =incReportService.IncLineDayNumber(oldparams);
			listColumn.add(newList);
		}

		if(endDate==null){
			oldparams.put("endDate", Utils.parse(new  Date(),"yyyy-MM"));
			List<Object> newList =incReportService.IncLineDayNumber(oldparams);
			codeList.add(Utils.parse(new  Date(),"yyyy-MM"));
			listColumn.add(newList);
		}else{
//			oldparams.put("endDate",endDate);
			oldparams.put("endDate",Utils.parse(endDate,"yyyy-MM"));
			List<Object> newList =incReportService.IncLineDayNumber(oldparams);
			codeList.add(Utils.parse(endDate,"yyyy-MM"));
			listColumn.add(newList);
		}
		list.add(codeList);
		list.add(listColumn);
//		List<Object> newList =incReportService.IncLineDayNumber(params);
		model.addAttribute("params",params);
		model.addAttribute("data",JsonUtil.getJsonByObj(list));
		return "report/incident/IncYoyDayNumber";
	}



	/**
	 * 列表
	 */
	@RequestMapping("/IncColumnTypeTop10")
//	@RequiresPermissions("srminfo:list")
//	@SysLog("查询变更列表")
	public String IncColumnTypeTop10(@RequestParam Map<String, Object> params, Model model , HttpServletRequest request){
		params.put("fetchNumber",10);
		List<Object> list =incReportService.IncColumnTypeTop10(params);
		model.addAttribute("params",params);
		model.addAttribute("data",JsonUtil.getJsonByObj(list));
		return "report/incident/IncColumnTypeTop10";
	}



	/**
	 * 列表
	 */
	@RequestMapping("/IncLineMonthNumber")
//	@RequiresPermissions("srminfo:list")
//	@SysLog("查询变更列表")
	public String IncLineMonthNumber(@RequestParam Map<String, Object> params, Model model , HttpServletRequest request){
		Date endDate= (Date) params.get("endDate");
		if(endDate==null){
			params.put("endDate",new  Date());
		}
		List<Object> list =incReportService.IncLineMonthNumber(params);
		model.addAttribute("params",params);
		model.addAttribute("data",JsonUtil.getJsonByObj(list));
		return "report/incident/IncLineMonthNumber";
	}



	/**
	 * 列表
	 */
	@RequestMapping("/IncYoyMonthNumber")
//	@RequiresPermissions("srminfo:list")
//	@SysLog("查询变更列表")
	public String IncYoyMonthNumber(@RequestParam Map<String, Object> params, Model model , HttpServletRequest request){
		List list =new ArrayList();
		List codeList  =new ArrayList();
		List listColumn = new ArrayList();
		Date beginDate= (Date) params.get("beginDate");
		Date endDate= (Date) params.get("endDate");
		Map<String, Object> oldparams=new HashMap<String, Object>();
		if(beginDate==null){
			oldparams.put("endDate",new Date());
			codeList.add(Utils.formatDate(new Date()));
			List<Object> newList =incReportService.IncLineMonthNumber(oldparams);
			listColumn.add(newList);
		}else{
			oldparams.put("endDate",beginDate);
			codeList.add(Utils.formatDate(beginDate));
			List<Object> newList =incReportService.IncLineMonthNumber(oldparams);
			listColumn.add(newList);
		}

		if(endDate==null){
			oldparams.put("endDate",new Date());
			codeList.add(Utils.formatDate(new Date()));
			List<Object> newList =incReportService.IncLineMonthNumber(oldparams);
			listColumn.add(newList);
		}else{
			oldparams.put("endDate",endDate);
			codeList.add(Utils.formatDate(endDate));
			List<Object> newList =incReportService.IncLineMonthNumber(oldparams);
			listColumn.add(newList);
		}
		list.add(codeList);
		list.add(listColumn);
//		List<Object> list =incReportService.IncLineMonthNumber(params);
		model.addAttribute("params",params);
		model.addAttribute("data",JsonUtil.getJsonByObj(list));
		return "report/incident/IncYoyMonthNumber";
	}



	/**
	 * 列表
	 */
	@RequestMapping("/IncChainMonthNumber")
//	@RequiresPermissions("srminfo:list")
//	@SysLog("查询变更列表")
	public String IncChainMonthNumber(@RequestParam Map<String, Object> params, Model model , HttpServletRequest request){
		Date endDate= (Date) params.get("endDate");
		if(endDate==null){
			params.put("endDate",new  Date());
		}
		List<Object> list =incReportService.IncLineMonthNumber(params);
		model.addAttribute("params",params);
		model.addAttribute("data",JsonUtil.getJsonByObj(list));
		return "report/incident/IncChainMonthNumber";
	}




	/**
	 * 列表
	 */
	@RequestMapping("/IncColumnOperatorNumTop10")
//	@RequiresPermissions("srminfo:list")
//	@SysLog("查询变更列表")
	public String IncColumnOperatorNumTop10(@RequestParam Map<String, Object> params, Model model , HttpServletRequest request){
		params.put("fetchNumber",10);
		List<Object> list =incReportService.IncColumnOperatorNumTop10(params);
		model.addAttribute("params",params);
		model.addAttribute("data",JsonUtil.getJsonByObj(list));
		return "report/incident/IncColumnOperatorNumTop10";
	}



	/**
	 * 列表
	 */
	@RequestMapping("/IncColumnGroupSolvedTop10")
//	@RequiresPermissions("srminfo:list")
//	@SysLog("查询变更列表")
	public String IncColumnGroupSolvedTop10(@RequestParam Map<String, Object> params, Model model , HttpServletRequest request){
		params.put("fetchNumber",10);
		List<Object> list =incReportService.IncColumnGroupSolvedTop10(params);
		model.addAttribute("params",params);
		model.addAttribute("data",JsonUtil.getJsonByObj(list));
		return "report/incident/IncColumnGroupSolvedTop10";
	}
}
